|
|
 |
|
|
|
|
If depth <= 0 Then
x2 = x1 + dist * Cos(theta)
y2 = y1 + dist * Sin(theta)
picCanvas.Line (x1, y1)-(x2, y2)
x1 = x2
y1 = y2
Exit Sub
End If
' Recursively draw the edge. dist = dist * ScaleFactor
For i = 1 To NUM_GENERATOR_ANGLES
theta = theta + GeneratorDTheta(i)
DrawFlakeEdge depth - 1, x1, y1, theta, dist
Next i
End Sub |
|
|
|
|
|
|
|
|
You can use the DrawFlakeEdge subroutine to draw each of the edges in the curve's initiator. The following Visual Basic code loops through the initiator's coordinates stored in the InitiatorX() and InitiatorY() arrays and draws the edges of the snowflake. The ATan2 function takes as parameters dy and dx, the changes in a line segment's Y and X coordinates. It returns the angle with tangent dy / dx. |
|
|
|
 |
|
|
|
|
' Draw the snowflake. For i = 1 To NUM_INITIATOR_POINTS
x1 = InitiatorX(i - 1)
y1 = InitiatorY(i - 1)
x2 = InitiatorX(i)
y2 = InitiatorY(i)
dx = x2 - x1
dy = y2 - y1
theta = ATan2(dy, dx)
DrawFlakeEdge depth, x1, y1, _
theta, length
Next i |
|
|
|
|
|
|
|
|
With only a little more work, you can make the generator more general. When the program recursively breaks up a line segment, you can allow the program to turn by angles |
|
|
|
|
|
|
|
|
Figure 10.8
A snowflake generator beginning with a 45-degree turn. |
|
|
|
|
|